package com.itheima.a05myobjectstream;

import java.io.*;

public class ObjectStreamDemo1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //熟悉序列化对象

        //创建序列化流对象
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("myio\\stu.txt"));
        //写出（将学生对象信息序列化到指定文件）
        oos.writeObject(new Student("zhangsan",19));
        //关流
        oos.close();

        //反序列化流
        //创建对象
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("myio\\stu.txt"));
        //读取
        Student o = (Student)ois.readObject();
        System.out.println(o.getAge());
        ois.close();

    }
}
